package chapter10;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class MyCatDemo {
    public static void main(String[] args) throws SQLException {
        Connection myCatConn = null;
        PreparedStatement ps = null;
        String mycatUrl = "jdbc:mysql://localhost:8066/redisDemo";
        String mycatUser = "root";
        String mycatPassword = "123456";
        String sql = "insert into student(id,name,age,score) values(?,'test',18,100)";
        try {
            myCatConn = DriverManager.getConnection(mycatUrl, mycatUser, mycatPassword);
            ps = myCatConn.prepareStatement(sql);
            ps.setInt(1, 1);
            ps.addBatch();
            ps.setInt(1, 2);
            ps.addBatch();
            ps.setInt(1, 3);
            ps.addBatch();
            ps.executeBatch();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        } finally {
            if (ps != null) {
                ps.close();
            }
            if (myCatConn != null) {
                myCatConn.close();
            }
        }
    }

}
